#!/usr/bin/env python3

res = []

#  def register(func):
    #  """加载时运行"""
    #  print("running register{}".format(func))
    #  res.append(func)
    #  return func

def register(func):
    """加载时不运行, 被装饰函数被调用时才执行"""
    def inner():
        print("running register {}".format(func.__name__))
        res.append(func)
        func()
    return inner

@register
def f1():
    print("running f1()")

@register
def f2():
    print("running f2()")

def f3():
    print("running f3()")

@register
def f4():
    print("running f4()")

def main():
    print('running main()')
    print("before: {}".format(res))
    f1()
    f2()
    f3()
    f4()
    print("after: {}".format(res))

from deco_strategy import func_reg

@func_reg
def good_morninng():
    print('hello world')
    fl = len(func_reg.promos)
    print(func_reg.promos)
    print("now there {0} function{1} registered".format(fl,
        's' if fl > 1 else ''))

if __name__ == "__main__":
    #  main()
    good_morninng()
